# _*_ coding:utf-8 _*_
# @Time  : 2023.05.13
# @Author: zizlee
import random


class VarietyConstants:
    GROUPS = {
        6: '经济数据',
        7: '金融数据',
        1: '股指国债',
        8: '金融期货',
        2: '能源化工',
        3: '有色金属',
        4: '黑色系',
        5: '农产品'
    }

    SCOPES = {
        'S00': '上市交易',
        'S01': '文章研报',
        'S02': '短线策略',
        'S03': '中长策略',
        'S04': '行业数据',
        'S05': '定制数据',
        'S06': '计算平台',
        'S07': '价差套利',
        'S08': '持仓分析',
    }
    SCOPE_MARKET = 'S00'
    SCOPE_REPORT = 'S01'
    SCOPE_SHORT_STRATEGY = 'S02'
    SCOPE_LONG_STRATEGY = 'S03'
    SCOPE_DATALIB = 'S04'
    SCOPE_FLEX_DATALIB = 'S05'
    SCOPE_CALCULATE_PLAT = 'S06'
    SCOPE_SPREAD_ARBITRAGE = 'S07'
    SCOPE_POSITION_ANALYSIS = 'S08'

    INACTIVE_GROUPS = [7, 1]
    
    _variety = {}

    @classmethod
    def is_in(cls, code):
        return code in cls._variety.keys()

    @classmethod
    def set_variety_dict(cls, v_dict):
        cls._variety = v_dict

    @classmethod
    def get_variety_name(cls, code):
        return cls._variety.get(code, '其他')

    @classmethod
    def group_name(cls, group_id: int):
        return cls.GROUPS.get(group_id, '未知')

    @classmethod
    def scope_name(cls, scope_key: str):
        return cls.SCOPES.get(scope_key, '未知')


class AliasVariety:
    # 前端->后端
    REPORT_ALIAS = {
        'A':  'RABMY',
        'B':  'RABMY',
        'M':  'RABMY',
        'Y':  'RABMY',
        'AG': 'RAUAG',
        'AU': 'RAUAG',
        'C':  'RDCCS',
        'CS': 'RDCCS',
        'JR': 'RJILR',
        'RR': 'RJILR',
        'LR': 'RJILR',
        'OI': 'ROIMS',
        'RM': 'ROIMS',
        'RS': 'ROIMS',
        'FG': 'RFGSA',
        'SA': 'RFGSA',
        'CF': 'RCFCY',
        'CY': 'RCFCY',
        'IF': 'RIFHC',
        'IH': 'RIFHC',
        'IC': 'RIFHC',
        'TS': 'RZTGZ',
        'TF': 'RZTGZ',
        'T': 'RZTGZ',
        'TL': 'RZTGZ',
        'J': 'RZJMJ',
        'JM': 'RZJMJ',
        'SF': 'RSMSF',
        'SM': 'RSMSF',
        'AL': 'RALAO',
        'AO': 'RALAO'
    }
    # 后端->前端
    REPORT_ALIAS_REVERSE = {
        'RABMY': random.choice(['A', 'B', 'M', 'Y']),  # 豆一,豆二,豆粕,豆油(豆类)
        'RAUAG': random.choice(['AU', 'AG']),  # 黄金,白银(贵金属)
        'RFGSA': random.choice(['FG', 'SA']),  # 玻璃,纯碱(纯碱玻璃)
        'ROIMS': random.choice(['OI', 'RM', 'RS']),  # 菜油,菜粕,菜籽(菜籽系)
        'RJILR': random.choice(['JR', 'RI', 'LR']),  # 粳稻,早稻,晚稻(谷物类)
        'RDCCS': random.choice(['C', 'CS']),  # 玉米,玉米淀粉(玉米系)
        'RCFCY': random.choice(['CF', 'CY']),  # 棉花,棉纱(棉系)
        'RIFHC': random.choice(['IF', 'IH', 'IC']),  # 沪深300,上证50,中证500
        'RZTGZ': random.choice(['TS', 'TF', 'T', 'TL']),  # 2,5,10,30年国债
        'RZJMJ': random.choice(['J', 'JM']),  # 焦炭,焦煤
        'RSMSF': random.choice(['SF', 'SM']),  # 硅铁,锰硅
        'RALAO': random.choice(['AL', 'AO'])   # 沪铝,氧化铝
    }

    def report_alias(self, v):
        return self.REPORT_ALIAS.get(v, v)

    def report_alias_reverse(self, v):
        return self.REPORT_ALIAS_REVERSE.get(v, v)

    def report_alias_many(self, v_list):
        for i, v in enumerate(v_list):
            v_list[i] = self.REPORT_ALIAS.get(v, v)
        return v_list

    def report_alias_many_reverse(self, v_list):
        for i, v in enumerate(v_list):
            v_list[i] = self.REPORT_ALIAS_REVERSE.get(v, v)
        return v_list
